//
//  UIViewController+Skip.m
//  GK
//
//  Created by Seven on 2018/12/22.
//  Copyright © 2018年 Seven. All rights reserved.
//

#import "UIViewController+Skip.h"

@implementation UIViewController (Skip)

+ (UIViewController *)currentTopViewController {
    UIViewController *resultVC;
    resultVC = [self _topViewController:[[UIApplication sharedApplication].keyWindow rootViewController]];
    while (resultVC.presentedViewController) {
        resultVC = [self _topViewController:resultVC.presentedViewController];
    }
    if (resultVC.presentedViewController) {
        resultVC = resultVC.presentedViewController;
    }
    return resultVC;
}

+ (UIViewController *)_topViewController:(UIViewController *)vc {
    if ([vc isKindOfClass:[UINavigationController class]]) {
        return [self _topViewController:[(UINavigationController *)vc topViewController]];
    }else {
        return vc;
    }
    return nil;
    
}
@end
